package com.course.app.transformer;

import com.course.app.api.data.TaskClassDTO;
import com.course.domain.model.TaskClass;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Created by Justin on 2017/5/30.
 */
public class TaskClassTransformer {

    public static Map<Integer, TaskClassDTO> toClassMap(List<TaskClass> taskClassList) {
        return taskClassList.stream()
                .map(TaskClassTransformer::toClass)
                .collect(Collectors.toMap(TaskClassDTO::getId, Function.identity()));
    }

    private static TaskClassDTO toClass(TaskClass taskClass) {
        TaskClassDTO classDTO = new TaskClassDTO();
        classDTO.setId(taskClass.getId());
        classDTO.setTitle(taskClass.getTitle());
        classDTO.setDetail(taskClass.getDetail());
        classDTO.setMinutes(taskClass.getMinutes());
        classDTO.setType(toType(taskClass.getType()));
        return classDTO;
    }

    private static TaskClassDTO.Type toType(TaskClass.Type type) {
        switch (type) {
            case CHINESE:
                return TaskClassDTO.Type.CHINESE;
            case ENGLISH:
                return TaskClassDTO.Type.ENGLISH;
            default:
                return null;
        }
    }
}
